#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#include <immintrin.h>
//#include <emmintrin.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define fi first
#define se second
#define pii pair<int,int>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983,Mod=998244353;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
int n,m;
string mp[N];
vector<int>vis[N];
int ans[22][22],MP[22][22];
signed main(){
	freopen("indian.in","r",stdin);
	freopen("indian.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	n=read(),m=read();
	For(i,1,n){
		cin>>mp[i];
		mp[i]=' '+mp[i];
	}For(i,0,n+1)vis[i].resize(m+2);
	bool flag=0;
	if(n*m<=20){
		int mn=1e16;
		For(j,0,(1<<(n*m))-1){
			int res=0;
			For(x,1,n){
				For(y,1,m){
					MP[x][y]=0;
					if(j&(1<<((x-1)*m+y-1)))if(mp[x][y]=='#')MP[x][y]=1,res++;
				}
			}
//			if(res>mn) continue;
			bool flag=0;
			For(x,1,n){
			For(y,1,m){
				if(mp[x][y]=='#'){
					if(MP[x][y]||MP[x-1][y]||MP[x+1][y]||MP[x][y-1]||MP[x][y+1]);
					else flag=1;
				}
			}
			}if(flag) continue;
			if(res<=mn){
				
				For(x,1,n) For(y,1,m) ans[x][y]=MP[x][y];
				mn=res;
			}
		}
		For(i,1,n){
			For(j,1,m) if(mp[i][j]=='#')printf("%d",ans[i][j]);else printf(".");
			if(i!=n)puts("");
		}return 0;
	} 
	For(i,1,n){
		For(j,1,m){
			if(mp[i][j]=='#'){
				vis[i][j]=2; 
			}else flag=1;
		}
	}
	if(!flag){
		For(i,1,n)For(j,1,m) vis[i][j]=0;
		For(i,1,n)For(j,1,n){
			if(i%4==1&&j%4==2)vis[i][j]=2;
			if(i%4==2&&j%4==0)vis[i][j]=2;
			if(i%4==3&&j%4==1)vis[i][j]=2;
			if(i%4==0&&j%4==3)vis[i][j]=2;
		}
		For(i,1,n){
			For(j,1,m) if(mp[i][j]=='#')printf("%d",(vis[i][j]==2?1:0));else printf(".");
			if(i!=n)puts("");
		}return 0;
	}flag=0;
	For(i,1,n)For(j,1,m){
		if(mp[i][j]=='#'){
			if(vis[i-1][j]||vis[i][j-1]||vis[i+1][j]||vis[i][j+1]){
				flag=1;
			}
		}
	} if(!flag){
		
		For(i,1,n){
			For(j,1,m) if(mp[i][j]=='#')printf("%d",1);else printf(".");
			if(i!=n)puts("");
		}return 0;
	}
	For(i,1,n)For(j,1,m) vis[i][j]=0;
	For(i,1,n)For(j,1,m){
		if(mp[i][j]=='#'&&(i*2+j)%5==2) vis[i][j]=2,vis[i][j-1]=vis[i-1][j]=vis[i+1][j]=vis[i][j+1]=1;
	}
	For(i,1,n)For(j,1,m){
		if(mp[i][j]=='#'&&!vis[i][j]) vis[i][j]=2,vis[i][j-1]=vis[i-1][j]=vis[i+1][j]=vis[i][j+1]=1;
	}
	For(i,1,n){
		For(j,1,m) if(mp[i][j]=='#')printf("%d",(vis[i][j]==2?1:0));else printf(".");
		if(i!=n)puts("");
	} flag=0;
	For(x,1,n)
	For(y,1,m){
		if(mp[x][y]=='#'){
			if(vis[x][y]==2||vis[x-1][y]==2||vis[x+1][y]==2||vis[x][y-1]==2||vis[x][y+1]==2);
			else{
				puts("NO");
				return 0;	
			}
		}
	}
	int ha=0,lu=0,sum=0;
	For(i,1,n)For(j,1,m){
		if(mp[i][j]=='#'){
			lu++;
			if(vis[i][j]==2) sum++;
			if(mp[i-1][j]!='#'){
				ha++;
			}
			if(mp[i+1][j]!='#'){
				ha++;
			}
			if(mp[i][j-1]!='#'){
				ha++;
			}
			if(mp[i][j+1]!='#'){
				ha++;
			}
		}
	}
	if(sum>(ha+lu)/5){
		puts("No");
		return 0;
	}
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

